package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbKnowledgeBasePushLogic;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface TbKnowledgeBasePushLogicDao {
    @Insert("<script>" +
            "insert into " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC + " " +
            "( "+
            "knowledge_base_key, " +
            "create_user, " +
            "create_time, " +
            "update_user, " +
            "update_time, " +
            "boardParamTypeName, " +
            "boardParamName, " +
            "boardParamTypeId, " +
            "boardParamId, " +
            "boardParamKey, " +
            "logicRule, " +
            "logicValue, " +
            "logicGroup, " +
            "sort, " +
            "remark " +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.knowledge_base_key}, " +
            "#{entity.create_user}, " +
            "#{entity.create_time}, " +
            "#{entity.update_user}, " +
            "#{entity.update_time}, " +
            "#{entity.boardParamTypeName}, " +
            "#{entity.boardParamName}, " +
            "#{entity.boardParamTypeId}, " +
            "#{entity.boardParamId}, " +
            "#{entity.boardParamKey}, " +
            "#{entity.logicRule}, " +
            "#{entity.logicValue}, " +
            "#{entity.logicGroup}, " +
            "#{entity.sort}, " +
            "#{entity.remark} " +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer batchInsert(@Param("entities") List<TbKnowledgeBasePushLogic> entities);

    @Insert("<script>" +
            "insert into " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC + " " +
            "( "+
            "knowledge_base_key, " +
            "create_user, " +
            "create_time, " +
            "update_user, " +
            "update_time, " +
            "boardParamTypeName, " +
            "boardParamName, " +
            "boardParamTypeId, " +
            "boardParamId, " +
            "boardParamKey, " +
            "logicRule, " +
            "logicValue, " +
            "logicGroup, " +
            "sort, " +
            "remark " +
            ")"+
            "values "+
            "<if test='entity != null'> " +
            "(" +
            "#{entity.knowledge_base_key}, " +
            "#{entity.create_user}, " +
            "#{entity.create_time}, " +
            "#{entity.update_user}, " +
            "#{entity.update_time}, " +
            "#{entity.boardParamTypeName}, " +
            "#{entity.boardParamName}, " +
            "#{entity.boardParamTypeId}, " +
            "#{entity.boardParamId}, " +
            "#{entity.boardParamKey}, " +
            "#{entity.logicRule}, " +
            "#{entity.logicValue}, " +
            "#{entity.logicGroup}, " +
            "#{entity.sort}, " +
            "#{entity.remark} " +
            ")"+
            "</if> " +
            "</script>"
    )
    Integer insert(@Param("entity") TbKnowledgeBasePushLogic entity);
    @Update("<script>" +
            "UPDATE " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC + " " +
            "SET " +
            "knowledge_base_key = #{entity.knowledge_base_key}, " +
            "create_user = #{entity.create_user}, " +
            "create_time = #{entity.create_time}, " +
            "update_user = #{entity.update_user}, " +
            "update_time = #{entity.update_time}, " +
            "boardParamTypeName = #{entity.boardParamTypeName}, " +
            "boardParamName = #{entity.boardParamName}, " +
            "boardParamTypeId = #{entity.boardParamTypeId}, " +
            "boardParamId = #{entity.boardParamId}, " +
            "boardParamKey = #{entity.boardParamKey}, " +
            "logicRule = #{entity.logicRule}, " +
            "logicValue = #{entity.logicValue}, " +
            "logicGroup = #{entity.logicGroup}, " +
            "sort = #{entity.sort}, " +
            "remark = #{entity.remark} " +
            "<foreach collection=\"entities\" item=\"entity\" separator=\";\"> " +
            "WHERE id = #{entity.id} " +
            "</foreach>" +
            "</script>")
    Integer batchUpdate(@Param("entities") List<TbKnowledgeBasePushLogic> entities);
    @Update("<script>" +
            "UPDATE " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC +
            " SET " +
            "knowledge_base_key = #{entity.knowledge_base_key}, " +
            "create_user = #{entity.create_user}, " +
            "create_time = #{entity.create_time}, " +
            "update_user = #{entity.update_user}, " +
            "update_time = #{entity.update_time}, " +
            "boardParamTypeId = #{entity.boardParamTypeId}, " +
            "boardParamTypeName = #{entity.boardParamTypeName}, " +
            "boardParamName = #{entity.boardParamName}, " +
            "boardParamId = #{entity.boardParamId}, " +
            "boardParamKey = #{entity.boardParamKey}, " +
            "logicRule = #{entity.logicRule}, " +
            "logicValue = #{entity.logicValue}, " +
            "logicGroup = #{entity.logicGroup}, " +
            "sort = #{entity.sort}, " +
            "remark = #{entity.remark} " +
            "<where> " +
            "<if test='entity.id != null'>id = #{entity.id}</if>" +
            "</where>" +
            "</script>")
    Integer update(@Param("entity") TbKnowledgeBasePushLogic entity);
    @Delete("<script>" +
            "delete from " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC +
            " where id = #{id} " +
            "</script>")
    Integer deleteById(@Param("id") Integer id);

    @Select("<script> " +
            "SELECT * " +
            "FROM " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC +
            " WHERE 1=1 " +
            "<if test='baseKey != null and baseKey != \"\"'> " +
            " AND knowledge_base_key = #{baseKey} " +
            "</if> " +
            " order by sort" +
            "</script>")
    List<TbKnowledgeBasePushLogic> getByBaseKey(@Param("baseKey")String baseKey);

    @Select("<script> " +
            "SELECT * " +
            "FROM " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC +
            " WHERE 1=1 " +
            "<if test='baseKeyList != null and !baseKeyList.isEmpty()'> " +
            " AND knowledge_base_key IN " +
            "<foreach collection='baseKeyList' item='baseKey' open='(' separator=',' close=')'> " +
            "#{baseKey} " +
            "</foreach> " +
            "</if>" +
            " ORDER BY sort" +
            "</script>")
    List<TbKnowledgeBasePushLogic> getKeyToLogicsByBaseKeyList(@Param("baseKeyList") List<String> baseKeyList);

    @Select("<script> " +
            "SELECT * " +
            "FROM " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC +
            " WHERE 1=1 " +
            "<if test='baseKeyList != null and !baseKeyList.isEmpty()'> " +
            " AND knowledge_base_key IN " +
            "<foreach item='item' index='index' collection='baseKeyList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach>" +
            "</if>" +
            " order by sort" +
            "</script>")
    List<TbKnowledgeBasePushLogic> getByBaseKeyList(@Param("baseKeyList") List<String> baseKeyList);

    @Select("<script> " +
            "SELECT * " +
            "FROM " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC +
            " WHERE 1=1 order by sort" +
            "</script>")
    List<TbKnowledgeBasePushLogic> getAll();

    @Update("<script> " +
            "DELETE " +
            "FROM " + DB7TableName.TB_KNOWLEDGE_BASE_PUSH_LOGIC +
            " WHERE 1=1 " +
            "<if test='baseKeyList != null and !baseKeyList.isEmpty()'> " +
            " AND knowledge_base_key IN " +
            "<foreach item='item' index='index' collection='baseKeyList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach>" +
            "</if>" +
            "</script>")
    Integer deleteByBaseKey(@Param("baseKeyList")List<String> baseKeyList);
}

